<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<meta name="viewport" id="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="format-detection" content="telephone=no" />
		<link rel="stylesheet" href="/static/webAPP/css/reset.css" type="text/css"/>
		<link href="/static/webAPP/css/my-indent.css" rel="stylesheet" type="text/css">
		<title>待发货</title>
		<style>
			.zjzz-buylist-btn3{
				background-Color:#F6F6F6;
				color:#FF9201;
			}
		</style>
	</head>
	<body>
		<div class="zjzz-buylist-wear">
			<div class="zjzz-buylist-top">
				<a href="/static/webAPP/personal-center.html" class="zjzz-buylist-t1"></a>
				<span class="zjzz-buylist-t2">我的订单</span>
				<span class="zjzz-buylist-t3">
					<span class="zjzz-buylist-t4"></span>
				</span>
			</div>
			<div class="zjzz-buylist-top2">			
				<a href="/static/webAPP/my-indent-all.html" class="zjzz-buylist-tp1">
					<i>全部</i>
				</a>
				<a href="/static/webAPP/my-indent-dfk.html" class="zjzz-buylist-tp1">
					<i>待付款</i>
					<span class="zjzz-buylist-tp3 payOrder-num">0</span>
				</a>
				<a href="/static/webAPP/my-indent-dfh.html" class="zjzz-buylist-tp1">
					<i class="zjzz-buylist-tp2">待发货</i>
					<span class="zjzz-buylist-tp3 deliverOrder-num">0</span>
				</a>
				<a href="/static/webAPP/my-indent-dsh.html" class="zjzz-buylist-tp1">
					<i>待收货</i>
					<span class="zjzz-buylist-tp3 receiveOrder-num">0</span>
				</a>
				<a href="/static/webAPP/my-indent-tkdd.html" class="zjzz-buylist-tp1">
					<i>退款订单</i>
				</a>
			</div>		
			<div class="zjzz-buylist-mid">
				<!--全部-->
				<div class="zjzz-buylist-m1">
					
				</div>
			</div>
		</div>

		<script src="/static/webAPP/js/jquery-1.8.3.min.js"></script>
		<script src="/static/webAPP/lib/mobile/layer.js"></script>
		<script>
			var userName = sessionStorage.getItem("sessionName")
			if (userName == null || userName == '' || userName == undefined) {
				layer.open({
					content: '是否去往登录界面？',
					btn: ['去登陆', '不要'],
					shadeClose: false,
					yes: function(index){
						window.location = "./login.html";
					}
				});
			}else{
				$.ajax({
					type: "get",
							//TODO:
					url: "/app/userInfo/" + userName,
					data: '',
					dataType: "json",
					success: function(mag){
						$(".payOrder-num").html(mag.data.bookOrderStatus.to_pay)
						$(".deliverOrder-num").html(mag.data.bookOrderStatus.to_deliver)
						$(".receiveOrder-num").html(mag.data.bookOrderStatus.to_receive)
						var user_id = mag.data.id
						var tag = ''
						$.ajax({
							type: "post",
							//TODO:
							url: "/app/bookOrder/getBookOrderList",
							data: {user_id: user_id,pageNum: 1,status: 1},
							dataType: "json",
							success: function(res){
								for (let i = 0; i < res.data.length; i++) {
									var tag1 = '<div class="zjzz-buylist-goods1"><div class="zjzz-buylist-gtime"><span class="zjzz-buylist-gtime1">'+ timestampToTime(res.data[i].create_date) +'</span><span class="zjzz-buylist-gtime2">待发货</span></div><a href="./indent-details.html?id='+ res.data[i].id +'"  class="zjzz-buylist-det"><div class="zjzz-buylist-gdetail"><span class="zjzz-buylist-gtit1 cart-title">订单编号：'+ res.data[i].id +'</span></div></a><span class="zjzz-buylist-goodsm_c"><i>已付总额：<i class="zjzz-buylist-gm4">'+ res.data[i].amount +'</i></i><i class="zjzz-buylist-btn_c"><a href="./refundBookOrder.html?id='+ res.data[i].id +'" class="zjzz-buylist-btn3">申请退款</a></i></span></div>'
									tag += tag1
								}
								$(".zjzz-buylist-m1").html(tag)
							}
						})

						var pageNum = 1
						$(window).scroll(function(){
							var scrollTop = $(this).scrollTop();    
							var scrollHeight = $(document).height();   
							var clientHeight = $(this).height();    
							if(scrollTop + clientHeight >= scrollHeight){
								pageNum ++
								$.ajax({
									type: "post",
											//TODO:
									url: "/app/bookOrder/getBookOrderList",
									data: {user_id: user_id,pageNum: pageNum,status: 1},
									dataType: "json",
									success: function(res){
										var data = res.data
										for (let i = 0; i < data.length; i++) {
											var tag1 = '<div class="zjzz-buylist-goods1"><div class="zjzz-buylist-gtime"><span class="zjzz-buylist-gtime1">'+ timestampToTime(res.data[i].create_date) +'</span><span class="zjzz-buylist-gtime2">待发货</span></div><a href="./indent-details.html?id='+ res.data[i].id +'"  class="zjzz-buylist-det"><div class="zjzz-buylist-gdetail"><span class="zjzz-buylist-gtit1 cart-title">订单编号：'+ res.data[i].id +'</span></div></a><span class="zjzz-buylist-goodsm_c"><i>已付总额：<i class="zjzz-buylist-gm4">'+ res.data[i].amount +'</i></i><i class="zjzz-buylist-btn_c"><a href="./indent-details.html?id='+ res.data[i].id +'" class="zjzz-buylist-btn3">申请退款</a></i></span></div>'
											tag += tag1
										}
										if (data.length != 10) {
											$(".zjzz-buylist-m1").html(tag + '<div style="text-align: center;color: #ccc;">已加载全部订单</div>')
										}else{
											$(".zjzz-buylist-m1").html(tag)
										}
									}
								})
							}
						});
					}
				})
			}

		//时间的转换封装
			function timestampToTime(timestamp) {
		        var date = new Date(timestamp * 1);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
		        Y = date.getFullYear() + '-';
		        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
		        D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
		        h = (date.getHours() < 10 ? '0' +date.getHours() : date.getHours()) + ':';
		        m = (date.getMinutes() < 10 ? '0' +date.getMinutes() : date.getMinutes()) + ':';
		        s = (date.getSeconds() < 10 ? '0' +date.getSeconds() : date.getSeconds());
		        return Y+M+D+h+m+s;
		    }
		</script>
	</body>
</html>
